package com.chixing.day02;

import java.util.Arrays;

/**
 * @author Y2014188432
 */
public class ArrayDemo {
    public static void main(String[] args) {
        int[] arr1 = new int[6];
        arr1[0] = 1;
        arr1[1] = 2;
        arr1[2] = 3;
        arr1[3] = 4;
        arr1[4] = 5;
        arr1[5] = 55;
        System.out.println("初始化的数组为\t\t"+Arrays.toString(arr1));
        // 0 和 2 交换位置
        int temp = arr1[0];
        arr1[0] = arr1[2];
        arr1[2] = temp;
        System.out.println("下标 0 和 2 交换后的数组为\t\t"+Arrays.toString(arr1));
        // 找数组最大值
        int max = arr1[0];
        for (int value : arr1) {
            max = Math.max(max, value);
        }
        System.out.println("数组最大值为"+max);
        //数组倒置
        System.out.println("倒置前数组为\t\t"+Arrays.toString(arr1));
        for (int i = 0; i < arr1.length/2; i++) {
            int end = arr1.length - 1 - i;
            int t = arr1[i];
            arr1[i] = arr1[end];
            arr1[end] = t;
        }
        System.out.println("倒置后数组为\t\t"+Arrays.toString(arr1));
        // 创建一个新的数组 b ,将 a 复制到 b
        int[] a = {13,15,67,24,68,36,19,42};
        int[] b = new int[a.length];
        int[] c = new int[10];
        for (int i = 0; i < a.length; i++) {
            b[i] = a[i];
        }
//        将a 数组中 前2个元素 复制到 c 数组的最后两个位置上；
//        将a 数组中 最后6个元素 复制到 c 前6个位置上
        int x = c.length - 2;
        for (int value : a) {
            if(x == c.length){
                x -= c.length;
            }
            c[x] = value;
            x ++;
        }
        System.out.println("数组a:\t"+Arrays.toString(a));
        System.out.println("数组b:\t"+Arrays.toString(b));
        System.out.println("数组c:\t"+Arrays.toString(c));

    }
}
